procedure prefix(s : string);

var 
	m, k, q : longint;
	
begin
	fillchar(p, sizeof(p), 0);
	m := length(s);
	p[1] := 0;
	k := 0;
	for q := 2 to m do begin
		while (k > 0) and (s[k + 1] <> s[q]) do k := p[k];
		if s[k + 1] = s[q] then inc(k);
		p[q] := k;
	end;
end;